package com.hbtt.sousou;

import java.util.Scanner;

/**
 * 
 * @author 窦瑞涛 
 * 菜单类
 */
public class Common {
	Scanner input = new Scanner(System.in);
	CardUtil cardutil = new CardUtil();
	
	String number = null;

	/**
	 * 一级菜单
	 */
	public void start() {
		MobileCard mobile = new MobileCard();
		System.out.println("******欢迎使用嗖嗖移动大厅********");
		System.out.println("1.用户登录  2.用户注册  3.使用嗖嗖 4.话费充值 5.资费说明 6.退出系统");
		System.out.println("--（如无账户，请先进行注册！）--");
		boolean o = true;
		while(o) {
			System.out.print("请选择：");
			int x = input.nextInt();
			switch (x) {
			case 1:
				o = false;
				while (true) {
					System.out.print("请输入手机卡号:");
					number = input.next();
					System.out.print("请输入密码:");
					String passWord = input.next();
					if (cardutil.isExistCard(number, passWord) == true) {
						cardMenu();
						break;
					}
				}
				break;
			case 2:
				o = false;
				registCard(mobile);
				break;
			case 3:
				o = false;
				System.out.print("请输入手机号码：");
				String number1 = input.next();
				cardutil.userSoso(number1);
				start();
				break;
			case 4:
				o = false;
				System.out.print("请输入充值卡号：");
				String number2 = input.next();
				double money = 0;
				System.out.print("请输入充值金额（元）：");
				while(true) {
				    money = input.nextDouble();
				    if(money<=10) {
					System.out.print("充值金额不得小于10元，请重新输入：");
				}else {
					break;
				}
				}
				cardutil.chargeMoney(number2, money);
				System.out.println(" ");
				start();
				break;
			case 5:
				o = false;
				cardutil.showDescripiton();
				System.out.println(" ");
				start();
				break;
			case 6:
				System.out.println("系统退出！");
				System.exit(0);
			default:
				System.out.println("请重新输入！");
			}	
			}
		    
		
	}

	/**
	 * 二级菜单类
	 */
	public void cardMenu() {
		System.out.println("******嗖嗖移动用户菜单******");
		System.out.println("1.本月账单查询");
		System.out.println("2.套餐余量查询");
		System.out.println("3.打印消费详单");
		System.out.println("4.套餐变更");
		System.out.println("5.办理退网");
		System.out.print("请选择（输入1~5选择功能，其他键返回上一级）");
		int y = input.nextInt();
		switch (y) {
		case 1:
			cardutil.showAmountDetail(number);
			System.out.println(" ");			
			cardMenu();
			break;
		case 2:
			cardutil.showRemainDetail(number);
			System.out.println(" ");	
			cardMenu();
			break;
		case 3:
			cardutil.printAmountDetail(number);
			System.out.println(" ");
			cardMenu();
			break;
		case 4:
			cardutil.changingPack(number);
			System.out.println(" ");
			cardMenu();
			break;
		case 5:
			cardutil.delCard(number);
			
		default:
			System.out.println(" ");
			start();
			break;
		}
	}

	public void registCard(MobileCard mobile) {
		String[] numbers = new String[9];
		System.out.println("***可选择的卡号***");
		for (int i = 0; i < 9; i++) {
			numbers[i] = cardutil.CreateNumber();
			System.out.print(i + 1 + "." + numbers[i] + " ");
			if ((i + 1) % 3 == 0) {
				System.out.println();
			}
		}
		System.out.print("请选择卡号(输入1-9的序号):");
		int h = input.nextInt();
		mobile.setCardNumber(numbers[h-1]);
		int x = 0;
		boolean boo = true;
		while(boo) {
			System.out.print("1.话唠套餐 2.网虫套餐 3.超人套餐   请选择套餐(输入序号)：");
		    x= input.nextInt();
			switch (x) {
			case 1:
				boo = false;
				mobile.setSerPackage(new TalkPackage(500, 0, 30, 58));
				break;
			case 2:
				boo = false;
				mobile.setSerPackage(new NetPackage(0, 3*1024, 0, 68));
				break;
			case 3:
				boo = false;
				mobile.setSerPackage(new SuperPackage(200, 1*1024, 50, 78));
				break;
			default:
				System.out.println("输入错误，请重新输入!");
				break;
			}
		}

		System.out.print("请输入姓名：");
		String name = input.next();
		mobile.setUserName(name);
		System.out.print("请输入密码：");
		String passWord = input.next();
		mobile.setPassWord(passWord);
		System.out.print("请输入预存话费金额（元）：");
		while (true) {
			double money = input.nextInt();
			if (money >= cardutil.createPack(x).getPrice()) {
				mobile.setMoney(money - cardutil.createPack(x).getPrice());
				System.out.println("注册成功！卡号:" + mobile.getCardNumber() + " 用户名:" + mobile.getUserName() + " 当前余额:"
						+ mobile.getMoney() + "元。");
				cardutil.createPack(x).showInfo();
				cardutil.addCard(numbers[h-1], mobile);
				break;
			} else {
				System.out.print("您预存的话费金额不足以支付本月固定套餐资费，请重新充值：");
			}
		}

		start();
	}

}
